[% setvar title Case ignoring eq and cmp operators %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Case ignoring eq and cmp operators</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Markus Peter &lt;<a href='mailto:warp@spin.de'>warp@spin.de</a>&gt;
  Date: 24 Aug 2000
  Last Modified: 25 Sep 2000
  Mailing List: <a href='mailto:perl6-language@perl.org'>perl6-language@perl.org</a>
  Number: 143
  Version: 2
  Status: Retired</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>Perl currently only has <code>eq</code> and <code>cmp</code> operators which work case-sensitively.
It would be a useful addition to add case-insensitive equivalents.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<a name='Problems with current ways to do it'></a><h2>Problems with current ways to do it</h2>
<p>Perl currently knows basically two methods for checking of equality of
strings case-insensitively:</p>
<pre> uc($a) eq uc($b)
 $a =~ /^$b$/i</pre>
<p>and for comparing them one:</p>
<pre> uc($a) cmp uc($b)</pre>
<p>The probably worst about these statements is that they look ugly. Also,
they further complicate statements and they are counter-intuitive for
beginners - why should I change the case of variables if I only want
to compare them?</p>
<p>The regexp mechanism has a case-insensitivity option (there's probably
no proper way to simulate it there I admit). With this in mind most
beginners will conclude the same is true for eq and cmp - after all
Perl is strong in text processing so how could such a feature miss?
Beginner code usually ends up using the case-insensitive regexps then
instead of the easier to read uppercase/equals combination.</p>
<a name='Proposal'></a><h2>Proposal</h2>
<p>We apply something similar to the regexp modifiers to <code>eq</code> and <code>cmp</code>
as well, after a slash. The above examples would then be</p>
<pre>  $a eq/i $b
  $a cmp/i $b</pre>
<p>This still leaves some room for future additions to eq and cmp if desired
(stupid example: like ignoring all white space in the comparison or
whatever comes up)</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>Probably has to be added to perl internals...</p>
<p>I wonder what will happen with overloads though - is eq/i a new operator
to overload or is the case-insensitivity somehow magically done by the
Perl interpreter even though eq was overloaded? This probably could lead
to problems...</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>perlop manpage for eq and cmp</p>
<p>String.equalsIgnoreCase() method in Java</p>
</div>
